//
//  POSStore.m
//  NewPro
//
//  Created by 何荧红 on 2019/4/28.
//  Copyright © 2019 何荧红. All rights reserved.
//

#import "POSStore.h"
#import "PostlistModel.h"

@implementation POSStore

#pragma mark 获取划拨规则URL
- (void)GetDivisionURLWithID:(NSString *)customId Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/merchant/getRuleURL",IP];
    NSDictionary *prams = @{
                            @"customId":customId
                            };
    [HttpTool postUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 获取终端列表数量
- (void)GetPOSCountWithID:(NSString *)customId Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/instance/count",IP];
    NSDictionary *prams = @{
                            @"customerId":customId
                            };
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 我的终端未激活
- (void)GetUnActivePosWithPrams:(NSDictionary *)prams Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/instance/list/unActive",IP];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 划拨POS
- (void)PostPOSWithPrams:(NSDictionary *)prams Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/pos/flow",IP];
    [HttpTool postUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 我的终端,审核中至已达标
- (void)GetMyPosReviewWithPrams:(NSDictionary *)prams Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/instance/list",IP];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 我的终端可回拨
- (void)GetCanBackFlowWithID:(NSString *)customerId Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/instance/backFlow",IP];
    NSDictionary *prams = @{
                            @"customerId":customerId
                            };
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}
#pragma mark 回拨列表详细
- (void)GetCanBackFlowDetailWithPrams:(NSDictionary *)prams andfromId:(NSString *)fromId Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/instance/backFlow/%@",IP,fromId];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            success(responseObject);
        }else{
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 我的终端去回拨
- (void)GoBackFlowWithPrams:(NSDictionary *)prams Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/backFlow/flow",IP];
    [HttpTool postUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}


#pragma mark 回拨历史记录
- (void)GetBackFlowHistoryWithPrams:(NSDictionary *)prams Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/backFlow/his",IP];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 回拨历史记录详情
- (void)GetBackFlowHistoryDetailWithPrams:(NSDictionary *)prams andID:(NSString *)fromid Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/backFlow/his/%@",IP,fromid];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 回拨记录
- (void)GetbackFlowListWithPrams:(NSDictionary *)prams Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/backFlow/records",IP];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *erro = [HttpTool inspectError:responseObject];
        if (erro == nil) {
            success(responseObject);
        }else{
            failure(erro);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 回拨记录详情
- (void)GetbackFlowListDetailWithPrams:(NSDictionary *)prams andID:(NSString *)fromid Success:(void(^)(NSDictionary *res))success Failure:(void(^)(NSError *error))failure{
    NSString *url = [NSString stringWithFormat:@"%@/api/backFlow/records/%@",IP,fromid];
    [HttpTool getUrlWithString:url parameters:prams success:^(id responseObject) {
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            success(responseObject);
        }else{
            failure(error);
        }
    }failure:^(NSError *error) {
        failure(error);
    }];
}

#pragma mark 回拨接受或拒绝
- (void)GoPutBackflowWithType:(NSString *)type andPrams:(NSDictionary *)prams Success:(void(^)(NSString *msg))success Failure:(void(^)(NSError *error))failure{
    NSString *RequestUrlString = [NSString stringWithFormat:@"%@/api/backFlow/confirm/%@",IP,type];
    [HttpTool putUrlWithString:RequestUrlString parameters:prams success:^(id responseObject) {
        NSError *error = [HttpTool inspectError:responseObject];
        if (error == nil) {
            success(responseObject[@"msg"]);
        }else{
            failure(error);
        }
    } failure:^(NSError *error) {
        failure(error);
    }];
}


@end
